//
//  MaterViewController.m
//  FoodFamily
//
//  Created by dlios on 15-6-20.
//  Copyright (c) 2015年 guoBang. All rights reserved.
//

#import "MaterViewController.h"

@interface MaterViewController ()

@end

@implementation MaterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor lightGrayColor];
    self.navigationItem.title = @"Food材料";
    self.materview = [[MaterView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.materview.movie = self.movie;
 
   // NSLog(@"   99999 %@",self.materview.movie.imagePathLandscape);
    self.materview.TblSeasoningarray = [NSMutableArray array];
    //NSLog(@"self.materview.movie = %@",self.materview.movie);
    [self.view addSubview:self.materview];
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(doFinished)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    [self AFN];
}
-(void)AFN{
NSString *string = [NSString stringWithFormat:@"http://121.41.88.194:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=%@&type=1&phonetype=0&is_traditional=0",self.movie.vegetable_id];    [AFNGetDataValue getDataAFN:string block:^(NSMutableDictionary *dataDic) {
    
    
        self.beandic = [NSMutableDictionary dictionary];
        self.dataarray = [NSMutableArray array];
    self.ArrayTblSeasoning = [NSMutableArray array];
        self.beandic = [dataDic objectForKey:@"bean"];
        NSMutableArray *array = [dataDic objectForKey:@"data"];
        // NSLog(@"self.beandic = %@",self.beandic);
    //NSLog(@"dataDic ==%@",dataDic);

    NSMutableDictionary *dic = [NSMutableDictionary dictionary];//第一个字典
    dic = [array firstObject];
    

    
    self.mate = [[Mater alloc]init];
    self.mate.imagePath = [dic objectForKey:@"imagePath"];
    self.mate.materialName = [dic objectForKey:@"materialName"];
    self.materview.mat= self.mate;
    
    
    
    NSMutableDictionary *TblSeasoningdic= [NSMutableDictionary dictionary];//第二个字典
    TblSeasoningdic = [array lastObject];// 数组中的最后一个是字典 用字典接收
    //NSLog(@"TblSeasoningdic ==%@",TblSeasoningdic);
    
    NSMutableArray *array1 = [TblSeasoningdic objectForKey:@"TblSeasoning"];//根据关键字从字典中取出数组
 
    
    for (NSMutableDictionary *dic in array1) {//遍历数组中的字典
        Mater *mater = [[Mater alloc]init];
       
        mater.imagePath = [dic objectForKey:@"imagePath"];
        mater.materialName = [dic objectForKey:@"name"];
              // self.materview.mat = mater;
       
        [self.ArrayTblSeasoning addObject:mater];
            }
    self.materview.TblSeasoningarray = self.ArrayTblSeasoning;
    //NSLog(@"self.ArrayTblSeasoning.count = %ld",self.ArrayTblSeasoning.count);
    }];

    //[self.materview mater];
}
-(void)doFinished
{
    [self.navigationController popViewControllerAnimated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
